package player;

import java.awt.BorderLayout;
import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.border.TitledBorder;

import java.awt.Color;

import javax.swing.JTextArea;
import javax.swing.JButton;

import java.awt.GridLayout;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.Socket;
import java.net.UnknownHostException;

import javax.swing.JLabel;
import javax.swing.SwingConstants;
import javax.swing.UIManager;

public class PlayerFrame extends JFrame
{

	private JPanel contentPane;
	private Socket socket = null;
	public PrintWriter out = null;
	private BufferedReader in = null;

	/**
	 * Launch the application.
	 */
	public static void main(String[] args)
	{
		EventQueue.invokeLater(new Runnable() {
			public void run()
			{
				try
				{
					PlayerFrame frame = new PlayerFrame(4444,"localhost","Agnieszka");
					frame.setVisible(true);
				} catch (Exception e)
				{
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the frame.
	 */
	public PlayerFrame(int port, String IP, String name)
	{
		try
		{
			this.socket = new Socket(IP, port);
			out = new PrintWriter(socket.getOutputStream(), true);
	    	in = new BufferedReader(new InputStreamReader(socket.getInputStream()));
		} catch (UnknownHostException e)
		{
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e)
		{
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		setResizable(false);
		
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 900, 600);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		contentPane.setBackground(new Color(5,75,8));
		setContentPane(contentPane);
		contentPane.setLayout(null);
		
		JPanel pnlChat = new JPanel();
		pnlChat.setBackground(new Color(9,47,5));
		pnlChat.setBorder(new TitledBorder(UIManager.getBorder("TitledBorder.border"), "Chat", TitledBorder.LEADING, TitledBorder.TOP, null, new Color(51, 204, 51)));
		pnlChat.setBounds(594, 22, 278, 524);
		contentPane.add(pnlChat);
		pnlChat.setLayout(null);
		
		JTextArea txtaChatDisplay = new JTextArea();
		txtaChatDisplay.setBackground(new Color(192, 192, 192));
		txtaChatDisplay.setEditable(false);
		txtaChatDisplay.setBounds(10, 16, 258, 375);
		pnlChat.add(txtaChatDisplay);
		
		JTextArea txtaChat = new JTextArea();
		txtaChat.setBounds(10, 400, 258, 66);
		pnlChat.add(txtaChat);
		
		JButton btnSend = new JButton("Wyślij");
		btnSend.setBounds(10, 474, 258, 40);
		pnlChat.add(btnSend);
		
		JPanel pnlMe = new JPanel();
		pnlMe.setBorder(new TitledBorder(null, name, TitledBorder.LEADING, TitledBorder.TOP, null, null));
		pnlMe.setBounds(26, 340, 541, 205);
		contentPane.add(pnlMe);
		pnlMe.setLayout(new GridLayout(0, 5, 0, 0));
		
		JLabel lblCard1 = new JLabel("Card1");
		lblCard1.setHorizontalAlignment(SwingConstants.CENTER);
		pnlMe.add(lblCard1);
		
		JLabel lblCard2 = new JLabel("Card2");
		lblCard2.setHorizontalAlignment(SwingConstants.CENTER);
		pnlMe.add(lblCard2);
		
		JLabel lblCard3 = new JLabel("Card3");
		lblCard3.setHorizontalAlignment(SwingConstants.CENTER);
		pnlMe.add(lblCard3);
		
		JLabel lblCard4 = new JLabel("Card4");
		lblCard4.setHorizontalAlignment(SwingConstants.CENTER);
		pnlMe.add(lblCard4);
		
		JPanel pnlButtons = new JPanel();
		pnlMe.add(pnlButtons);
		pnlButtons.setLayout(new GridLayout(0, 1, 0, 0));
		
		JButton btnCheck = new JButton("Check");
		pnlButtons.add(btnCheck);
		
		JButton btnBet = new JButton("Bet");
		pnlButtons.add(btnBet);
		
		JButton btnRaise = new JButton("Raise");
		pnlButtons.add(btnRaise);
		
		JButton btnCall = new JButton("Call");
		pnlButtons.add(btnCall);
		
		JButton btnFold = new JButton("Fold");
		pnlButtons.add(btnFold);
		
		JButton btnAllin = new JButton("All-in");
		pnlButtons.add(btnAllin);
		
		JButton btnDraw = new JButton("Wymień");
		pnlButtons.add(btnDraw);
		
		JPanel pnlPlayers = new JPanel();
		pnlPlayers.setBounds(26, 22, 541, 292);
		pnlPlayers.setBackground(new Color(5,75,8));
		contentPane.add(pnlPlayers);
		pnlPlayers.setLayout(new GridLayout(2, 3, 10, 10));
		
		JLabel lblPlayer_2 = new JLabel("Player_2");
		lblPlayer_2.setBackground(new Color(0, 102, 0));
		lblPlayer_2.setOpaque(true);
		lblPlayer_2.setHorizontalAlignment(SwingConstants.CENTER);
		pnlPlayers.add(lblPlayer_2);
		
		JLabel lblPlayer_3 = new JLabel("Player_3");
		lblPlayer_3.setBackground(new Color(0, 102, 0));
		lblPlayer_3.setHorizontalAlignment(SwingConstants.CENTER);
		lblPlayer_3.setOpaque(true);
		pnlPlayers.add(lblPlayer_3);
		
		JLabel lblPlayer_4 = new JLabel("Player_4");
		lblPlayer_4.setHorizontalAlignment(SwingConstants.CENTER);
		pnlPlayers.add(lblPlayer_4);
		
		JLabel lblPlayer_1 = new JLabel("Player_1");
		lblPlayer_1.setBackground(new Color(0, 102, 0));
		lblPlayer_1.setOpaque(true);
		lblPlayer_1.setHorizontalAlignment(SwingConstants.CENTER);
		pnlPlayers.add(lblPlayer_1);
		
		JPanel panel = new JPanel();
		pnlPlayers.add(panel);
		panel.setLayout(new GridLayout(3, 1, 0, 0));
		panel.setBackground(new Color(5,75,8));
		
		JLabel lblRound = new JLabel("Runda");
		lblRound.setForeground(new Color(50, 205, 50));
		lblRound.setBackground(new Color(9, 47, 5));
		lblRound.setOpaque(true);
		lblRound.setHorizontalAlignment(SwingConstants.CENTER);
		panel.add(lblRound);
		
		JLabel lblStake = new JLabel("Stawka");
		lblStake.setForeground(new Color(50, 205, 50));
		lblStake.setBackground(new Color(9, 47, 5));
		lblStake.setOpaque(true);
		lblStake.setHorizontalAlignment(SwingConstants.CENTER);
		panel.add(lblStake);
		
		JLabel lblPlayer5 = new JLabel("Player_5");
		lblPlayer5.setHorizontalAlignment(SwingConstants.CENTER);
		pnlPlayers.add(lblPlayer5);
	}
}
